﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AsyncCamera.Camera;
using Emgu.CV;
using Emgu.CV.Structure;
using System.Drawing;
using AsyncCamera.Camera.media;

namespace Incendios0_1.Camera.media.filters
{
    public class PrintDataFilter: MediaFilter
    {
        public Boolean CurrentDate;
        private Guid sourceId;
        public wpfdatamanager.AbstractCamera camera;

        public PrintDataFilter(MediaSource source)
            : base()
        {
            sourceId = source.GUID;
            plugIn[sourceId] = source;
            lastFrame[sourceId] = source.Frame;
            if (source.Frame != null)
            {
                Tick(null, null);
            }
            else
            {
                frame = null;
            }
        }

        protected override void Tick(object sender, EventArgs e)
        {
            Frame newFrame = plugIn[sourceId].Frame;
            if (newFrame != null && (lastFrame[sourceId] == null || lastFrame[sourceId].Id != newFrame.Id))
            {
                lastFrame[sourceId] = newFrame.Clone();
                Image<Bgr, Byte> img = lastFrame[sourceId].Image as Emgu.CV.Image<Bgr, Byte>;
                if (img == null)
                {
                    img = new Image<Bgr, Byte>(320, 240, new Bgr(255, 255, 255));
                    lastFrame[sourceId].Image = img;
                }
                MCvFont f = new MCvFont(Emgu.CV.CvEnum.FONT.CV_FONT_HERSHEY_COMPLEX, 0.5, 0.5);
                if (CurrentDate)
                    img.Draw(DateTime.Now.ToString("G"), ref f, new Point(25, 25), new Bgr(0, 0, 0));
                img.Draw(camera.cameraData.Name, ref f, new Point(25, 50), new Bgr(0, 0, 0));
                frame = lastFrame[sourceId];
            }
        }


    }
}
